package crypto.GM.MySM2;

import org.bouncycastle.asn1.gm.GMNamedCurves;
import org.bouncycastle.asn1.x9.X9ECParameters;
import org.bouncycastle.crypto.params.ECDomainParameters;
import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey;
import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey;

import java.security.KeyPair;

import static crypto.GM.SM2Util.generateKeyPair;
import static crypto.GM.SM2Util.sm2EncryptOld;

public class MySM2UtilTest {
    public static void main(String[] args) {
        //      生成密钥对
        X9ECParameters sm2ECParameters = GMNamedCurves.getByName("sm2p256v1");
        ECDomainParameters domainParameters = new ECDomainParameters(sm2ECParameters.getCurve(), sm2ECParameters.getG(), sm2ECParameters.getN());
        KeyPair kp = generateKeyPair();

        String e = sm2EncryptOld("hello world", (BCECPublicKey)kp.getPublic());

        MySM2Util sm2 = new MySM2Util();

//        sm2.encrypt("Enum", ((BCECPublicKey)kp.getPublic()).getQ() ); //用自建SM2进行加密
        BCECPrivateKey b = (BCECPrivateKey) kp.getPrivate();
        sm2.decrypt(e.getBytes(), b.getD() );  //用自建SM2解密标准密文报异常
    }
}
